package com.study.springboottest.design.singleton;

/**
 * 单例懒汉式
 * 加锁之后性能降低
 */
public class Mgr04 {

    private static Mgr04 INSTANCE;

    private Mgr04() {
    }

    public static synchronized Mgr04 getINSTANCE() {
        if (null == INSTANCE) {
            try {
                Thread.sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
            INSTANCE = new Mgr04();
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                System.out.println(Mgr04.getINSTANCE().hashCode());
            }).start();
        }
    }
}
